package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("permissions/limit")
public @caption("权限配置") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_limited") class SrvLimited implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("sl_id")    @primary  @notnull  @note("  ") Long slId;// 主键 非空     
	private @caption("所属项目") @column("sl_project")     @notnull  @relate("$slProject") @RelateClass(SrvProject.class)  @note("  ") Long slProject;// 非空     
 	private transient SrvProject $slProject;//关联对象[项目菜单]
	private @caption("所属角色") @column("sl_group")      @relate("$slGroup") @RelateClass(SrvGroup.class)  @note("  ") Long slGroup;//     
 	private transient SrvGroup $slGroup;//关联对象[组织部门]
	private @caption("权限值") @column("sl_limit")     @notnull  @note("  ") Integer slLimit;// 非空     
	 
	//默认构造函数
	public SrvLimited(){ 
	
	}
	
	//主键构造函数
	public SrvLimited(Long id){
		this.slId = id;
	}
	
	/**所有字段构造函数 
	 SrvLimited(
	 	Utils.getLong("slProject")//所属项目 [非空]
	 	,Utils.getLong("slGroup")//所属角色
	 	,Utils.getInteger("slLimit")//权限值 [非空]
	 )
	**/
	public SrvLimited(Long slProject,Long slGroup,Integer slLimit){
		this.slProject=slProject;
		this.slGroup=slGroup;
		this.slLimit=slLimit;
	}
	
	//设置非空字段
	public SrvLimited setNotNull(Long slProject,Integer slLimit){
		this.slProject=slProject;
		this.slLimit=slLimit;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvLimited slId(Long slId){
		this.slId = slId;
		this.setSeted(F.slId);
		return this;
	}
	/** 所属项目 [非空] [SrvProject]      **/
	public SrvLimited slProject(Long slProject){
		this.slProject = slProject;
		this.setSeted(F.slProject);
		return this;
	}
	/** 所属角色  [SrvGroup]      **/
	public SrvLimited slGroup(Long slGroup){
		this.slGroup = slGroup;
		this.setSeted(F.slGroup);
		return this;
	}
	/** 权限值 [非空]       **/
	public SrvLimited slLimit(Integer slLimit){
		this.slLimit = slLimit;
		this.setSeted(F.slLimit);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvLimited clone(){
		SrvLimited clone = new SrvLimited();
		clone.slProject=this.slProject;
		clone.slGroup=this.slGroup;
		clone.slLimit=this.slLimit;
		return clone;
	}
	
	
	/**
	 * 根据ID取权限配置
	 * @param id
	 * @return
	 */
	public static @api SrvLimited get(Long id){		
		return getSrvLimitedById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.slId = id;
	}
	
	/**
	 * 获取所有权限配置
	 * @return
	 */
	public static @api List<SrvLimited> list(Map params,Integer size){
		return getSrvLimitedList(params,size);
	}
	/**
	 * 获取权限配置分页
	 * @return
	 */
	public static @api Page<SrvLimited> page(Integer page,Integer size,Map params){
		return getSrvLimitedPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取权限配置
	 * @param params
	 * @return
	 */
	public static @api SrvLimited Get(Map params){
		return getSrvLimited(params);
	}
	/**
	 * 获取权限配置数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvLimitedCount(params);
	}
	/**
	 * 获取权限配置数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvLimitedEval(eval,params);
	}
	/**
	 * 获取权限配置图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvLimitedStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取权限配置图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvLimitedStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取权限配置
	 * @param id
	 * @return
	 */
	public static @api SrvLimited getSrvLimitedById(Long id){		
		return getSrvLimitedDao().getSrvLimitedById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.slId;
	}
	
	
	/**
	 * 根据ID取权限配置的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return null;
		}
		String value = null;
		if(value==null){
			SrvLimited srvLimited = get(id);
			if(srvLimited!=null){
				String strValue = srvLimited.getSlProject$();
				if(!"SlProject".equals("SlProject"))
					strValue+="("+srvLimited.getSlProject$()+")";
				value = strValue;
			}else{
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getSlProject$();
		if(!"SlProject".equals("SlProject"))
			keyValue+="("+this.getSlProject$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询权限配置对象
	 * @return
	 */
	public static @api SrvLimited find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("slId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or sl_project = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvLimited.getSrvLimited(params);
	}
	
	
	/**
	 * 根据关键字查询权限配置
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","sl_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("slId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or sl_project like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvLimited> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvLimited srvLimited:list){
			Map map = new HashMap();
			map.put("key",srvLimited.getSlId().toString());
			map.put("value", Utils.js(srvLimited.getKeyValue()));
			if(bObject==true)
				map.put("object",srvLimited);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有权限配置
	 * @return
	 */
	public static @api List<SrvLimited> getSrvLimitedList(Map params,Integer size){
		return getSrvLimitedDao().getSrvLimitedList(params,0,size);
	}
	
	/**
	 * 获取权限配置分页
	 * @return
	 */
	public static @api Page<SrvLimited> getSrvLimitedPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvLimitedDao().getSrvLimitedPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取权限配置
	 * @param params
	 * @return
	 */
	public static @api SrvLimited getSrvLimited(Map params){
		return getSrvLimitedDao().getSrvLimited(params);
	}
	
	/**
	 * 保存一个权限配置
	 * @param srvLimited
	 * @return
	 */
	public static @api SrvLimited saveSrvLimited(SrvLimited srvLimited){
		return getSrvLimitedDao().saveSrvLimited(srvLimited);
	}
	
	/**
	 * 根据条件更新权限配置
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvLimitedByConfirm(Map values, Map params){
		return getSrvLimitedDao().updateSrvLimitedByConfirm(values,params);
	}
	
	/**
	 * 修改一个权限配置
	 * @param srvLimited
	 * @return
	 */
	public static @api int updateSrvLimited(SrvLimited srvLimited){
		return getSrvLimitedDao().updateSrvLimited(srvLimited);
	}
	
	/**
	 * 更新权限配置非空字段
	 * @param srvLimited
	 */
	public static @api int updateSrvLimited$NotNull(SrvLimited srvLimited){
		return getSrvLimitedDao().updateSrvLimited$NotNull(srvLimited);
	}
	
	/**
	 * 获取权限配置数
	 * @return
	 */
	public static @api Long getSrvLimitedCount(Map params){
		return getSrvLimitedDao().getSrvLimitedCount(params);
	}
		
		
	/**
	 * 获取权限配置自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvLimitedEval(String eval,Map params){
		return getSrvLimitedDao().getSrvLimitedEval(eval,params);
	}
	/**
	 * 获取权限配置图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvLimitedStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvLimitedDao().getSrvLimitedStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvLimited.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvLimited.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvLimited(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvLimitedDao().updateSrvLimitedByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvLimited(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvLimitedDao().deleteSrvLimitedByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvLimitedDao().deleteSrvLimitedById(id);
	}
	
	
	/**
	 * 保存权限配置对象
	 * @param params
	 * @return
	 */
	public SrvLimited save(){
		if(this.getSlId()!=null)
			getSrvLimitedDao().updateSrvLimited(this);
		else
			return getSrvLimitedDao().saveSrvLimited(this);
		return this;
	}
	
	
	/**
	 * 更新权限配置对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvLimitedDao().updateSrvLimited$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
			getSrvLimitedDao().deleteSrvLimitedById(this.getSlId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvLimitedDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getSlId(){
		if(this.slId!=null){
			return this.slId;
		}
		return this.slId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getSlId$(){
		String strValue="";
		 strValue=Utils.string(this.getSlId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setSlId$(String strValue){
		if(Utils.empty(strValue)){
			this.slId=null;
			return;
		}
	 	this.slId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setSlId(Long slId){
		this.slId = slId;
		this.setSeted(F.slId);
	}
	
	
	
	
	/*******************************所属项目**********************************/	
	/**
	* 所属项目 [非空] [SrvProject]     
	**/
	public Long getSlProject(){
		if(this.slProject!=null){
			return this.slProject;
		}
		return this.slProject;
	}
	/**
	* 获取所属项目格式化(toString)
	**/
	public String getSlProject$(){
		String strValue="";
		if(this.getSlProject()!=null){
				strValue+=Utils.string(SrvProject.getKeyValue(this.getSlProject()));
		}			
	 	 return strValue;
	}
	/**
	* 根据所属项目反格式化
	**/
	public void setSlProject$(String strValue){
		if(Utils.empty(strValue)){
			this.slProject=null;
			return;
		}
		SrvProject item = SrvProject.find(strValue);
		if(item!=null){
			this.slProject = Utils.parseLong(item.getSpId());
		}
	}
	
	/**
	* 所属项目 [非空] [SrvProject]     
	**/
	public void setSlProject(Long slProject){
		this.slProject = slProject;
		this.setSeted(F.slProject);
	}
	
	
	
	
	/**
	* 获取关联对象[项目菜单]
	**/	 			
 	public SrvProject get$slProject(){
 		if(this.$slProject!=null)
 			return this.$slProject;
 		com.distribute.framework.model.SrvProject srvProject = null;
		if(this.getSlProject()!=null){
 			srvProject = SrvProject.get(this.getSlProject());
 		}
 		return srvProject;
	}
	/*******************************所属角色**********************************/	
	/**
	* 所属角色  [SrvGroup]     
	**/
	public Long getSlGroup(){
		if(this.slGroup!=null){
			return this.slGroup;
		}
		return this.slGroup;
	}
	/**
	* 获取所属角色格式化(toString)
	**/
	public String getSlGroup$(){
		String strValue="";
		if(this.getSlGroup()!=null){
				strValue+=Utils.string(SrvGroup.getKeyValue(this.getSlGroup()));
		}			
	 	 return strValue;
	}
	/**
	* 根据所属角色反格式化
	**/
	public void setSlGroup$(String strValue){
		if(Utils.empty(strValue)){
			this.slGroup=null;
			return;
		}
		SrvGroup item = SrvGroup.find(strValue);
		if(item!=null){
			this.slGroup = Utils.parseLong(item.getSgId());
		}
	}
	
	/**
	* 所属角色  [SrvGroup]     
	**/
	public void setSlGroup(Long slGroup){
		this.slGroup = slGroup;
		this.setSeted(F.slGroup);
	}
	
	
	
	
	/**
	* 获取关联对象[组织部门]
	**/	 			
 	public SrvGroup get$slGroup(){
 		if(this.$slGroup!=null)
 			return this.$slGroup;
 		com.distribute.framework.model.SrvGroup srvGroup = null;
		if(this.getSlGroup()!=null){
 			srvGroup = SrvGroup.get(this.getSlGroup());
 		}
 		return srvGroup;
	}
	/*******************************权限值**********************************/	
	/**
	* 权限值 [非空]      
	**/
	public Integer getSlLimit(){
		if(this.slLimit!=null){
			return this.slLimit;
		}
		return this.slLimit;
	}
	/**
	* 获取权限值格式化(toString)
	**/
	public String getSlLimit$(){
		String strValue="";
		 strValue=Utils.string(this.getSlLimit());
	 	 return strValue;
	}
	/**
	* 根据权限值反格式化
	**/
	public void setSlLimit$(String strValue){
		if(Utils.empty(strValue)){
			this.slLimit=null;
			return;
		}
		 	//此处未实现
		 	this.slLimit=Utils.parseInteger(strValue);
	}
	
	/**
	* 权限值 [非空]      
	**/
	public void setSlLimit(Integer slLimit){
		this.slLimit = slLimit;
		this.setSeted(F.slLimit);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvLimited.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvLimited.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvLimited.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvLimited.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvLimited.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvLimited.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvLimited.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvLimited.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvLimited.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvLimited.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvLimited.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvLimited.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvLimited.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M slId(Object slId){if(proxy)return proxy().slId(slId);  this.put("slId", slId);return this;};
	 	/** and sl_id is null */
 		public M slIdNull(){if(proxy)return proxy().slIdNull();if(this.get("slIdNot")==null)this.put("slIdNot", "");this.put("slId", null);return this;};
 		/** not .... */
 		public M slIdNot(){if(proxy)return proxy().slIdNot();this.put("slIdNot", "not");return this;};
 		public M slIdNotNull(){if(proxy)return proxy().slIdNotNull();this.put("slIdNot", "not");this.put("slId", null);return this;};
 		public M slIdNot(Object slId){if(proxy)return proxy().slIdNot(slId);this.put("slIdNot", "not");this.put("slId", slId);return this;};
		/** and sl_id <= ? */
		public M slIdMin(Object min){if(proxy)return proxy().slIdMin(min);this.put("slIdMin", min);return this;};
		/** and sl_id >= ? */
		public M slIdMax(Object max){if(proxy)return proxy().slIdMax(max);this.put("slIdMax", max);return this;};
		public M slIdIn(String ids){
			if(proxy)return proxy().slIdIn(ids);  this.put("slIdIn", ids);return this;
		};	
		public M slProject$on(SrvProject.M value){if(proxy)return proxy().slProject$on(value);this.put("SlProject", value);value.put("on", "sl_project");return this;};
		/** 所属项目 [非空] [SrvProject]      **/
		public M slProject(Object slProject){if(proxy)return proxy().slProject(slProject);  this.put("slProject", slProject);return this;};
	 	/** and sl_project is null */
 		public M slProjectNull(){if(proxy)return proxy().slProjectNull();if(this.get("slProjectNot")==null)this.put("slProjectNot", "");this.put("slProject", null);return this;};
 		/** not .... */
 		public M slProjectNot(){if(proxy)return proxy().slProjectNot();this.put("slProjectNot", "not");return this;};
 		public M slProjectNotNull(){if(proxy)return proxy().slProjectNotNull();this.put("slProjectNot", "not");this.put("slProject", null);return this;};
 		public M slProjectNot(Object slProject){if(proxy)return proxy().slProjectNot(slProject);this.put("slProjectNot", "not");this.put("slProject", slProject);return this;};
		public M slProjectIn(String ids){
			if(proxy)return proxy().slProjectIn(ids);  this.put("slProjectIn", ids);return this;
		};	
		public M slGroup$on(SrvGroup.M value){if(proxy)return proxy().slGroup$on(value);this.put("SlGroup", value);value.put("on", "sl_group");return this;};
		/** 所属角色  [SrvGroup]      **/
		public M slGroup(Object slGroup){if(proxy)return proxy().slGroup(slGroup);  this.put("slGroup", slGroup);return this;};
	 	/** and sl_group is null */
 		public M slGroupNull(){if(proxy)return proxy().slGroupNull();if(this.get("slGroupNot")==null)this.put("slGroupNot", "");this.put("slGroup", null);return this;};
 		/** not .... */
 		public M slGroupNot(){if(proxy)return proxy().slGroupNot();this.put("slGroupNot", "not");return this;};
 		public M slGroupNotNull(){if(proxy)return proxy().slGroupNotNull();this.put("slGroupNot", "not");this.put("slGroup", null);return this;};
 		public M slGroupNot(Object slGroup){if(proxy)return proxy().slGroupNot(slGroup);this.put("slGroupNot", "not");this.put("slGroup", slGroup);return this;};
		public M slGroupIn(String ids){
			if(proxy)return proxy().slGroupIn(ids);  this.put("slGroupIn", ids);return this;
		};	
		/** 权限值 [非空]       **/
		public M slLimit(Object slLimit){if(proxy)return proxy().slLimit(slLimit);  this.put("slLimit", slLimit);return this;};
	 	/** and sl_limit is null */
 		public M slLimitNull(){if(proxy)return proxy().slLimitNull();if(this.get("slLimitNot")==null)this.put("slLimitNot", "");this.put("slLimit", null);return this;};
 		/** not .... */
 		public M slLimitNot(){if(proxy)return proxy().slLimitNot();this.put("slLimitNot", "not");return this;};
 		public M slLimitNotNull(){if(proxy)return proxy().slLimitNotNull();this.put("slLimitNot", "not");this.put("slLimit", null);return this;};
 		public M slLimitNot(Object slLimit){if(proxy)return proxy().slLimitNot(slLimit);this.put("slLimitNot", "not");this.put("slLimit", slLimit);return this;};
		public M slLimitIn(String ids){
			if(proxy)return proxy().slLimitIn(ids);  this.put("slLimitIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有权限配置 **/
		public @api List<SrvLimited> list(Integer size){			
			return getSrvLimitedList(this,size);
		}
		/** 获取权限配置分页 **/
		public @api Page<SrvLimited> page(Integer page,Integer size){			
			return getSrvLimitedPage(page, size , this);
		}
		/** 根据查询条件取权限配置 **/
		public @api SrvLimited get(){			
			return getSrvLimited(this);
		}
		/** 获取权限配置数 **/
		public @api Long count(){			
			return getSrvLimitedCount(this);
		}
		/** 获取权限配置表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvLimitedEval(strEval,this);
		}
		/** 获取权限配置统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvLimitedStats(this,sumKey,groupKey,dateType);
		}
		/** 获取权限配置统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvLimitedStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvLimited(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvLimited(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String slId="slId";
		/** 所属项目 [非空] [SrvProject]      **/
		public final static @type(Long.class)  String slProject="slProject";
		/** 所属角色  [SrvGroup]      **/
		public final static @type(Long.class)  String slGroup="slGroup";
		/** 权限值 [非空]       **/
		public final static @type(Integer.class)  String slLimit="slLimit";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		slId("sl_id"),
		slProject("sl_project"),
		slGroup("sl_group"),
		slLimit("sl_limit"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取权限配置数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvLimited.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvLimited.getSrvLimited(params);
			else
				value = SrvLimited.getSrvLimitedList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvLimited.where().slId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvLimited.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getSlId());
		Utils.fms(map,simple?"id":"slId",this.getSlId(),this.getSlId$());
		Utils.fms(map,simple?"project":"slProject",this.getSlProject(),this.getSlProject$());
		Utils.fms(map,simple?"group":"slGroup",this.getSlGroup(),this.getSlGroup$());
		Utils.fms(map,simple?"limit":"slLimit",this.getSlLimit(),this.getSlLimit$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("slId",this.getSlId());
		map.put("slProject",this.getSlProject());
		map.put("slGroup",this.getSlGroup());
		map.put("slLimit",this.getSlLimit());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvLimited fromMap(Map map){
		SrvLimited srvLimited = new SrvLimited();
		srvLimited.slId = Utils.parseLong(map.get("slId"));
		srvLimited.slProject = Utils.parseLong(map.get("slProject"));
		srvLimited.slGroup = Utils.parseLong(map.get("slGroup"));
		srvLimited.slLimit = Utils.parseInteger(map.get("slLimit"));
		return srvLimited;
	}
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvLimited old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/2008112220121595877803.png";
	}
	public static String getIconfont(){
		return "icon-yaochi1";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,SrvLimited.M params){
		if(params==null)params=new SrvLimited.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/permissions/limit.edit.html?";
		if(params.get("slId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("slId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/permissions/limit.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.slId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvLimited.ACT act,SrvLimited.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvLimited.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvLimited.ACT act,SrvLimited.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvLimited.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvLimitedDao getSrvLimitedDao(){
		return Utils.getBean("srvLimitedDao");
	};
	
}